package ar.uade.edu.fain.ad.client.delegate.rmi;

import java.rmi.RemoteException;
import java.util.List;

import ar.uade.edu.fain.ad.client.delegate.AdministracionDelegate;
import ar.uade.edu.fain.ad.client.delegate.rmi.util.ServiceLocator;
import ar.uade.edu.fain.ad.client.exception.UnavailableServerException;
import ar.uade.edu.fain.ad.common.exception.OrdenCompraInexistenteException;
import ar.uade.edu.fain.ad.common.exception.ProductoInexistenteException;
import ar.uade.edu.fain.ad.common.remote.SwingProcessRemoto;
import ar.uade.edu.fain.ad.common.transfer.ImportacionRemitoVO;
import ar.uade.edu.fain.ad.common.transfer.NotaDevolucionVO;
import ar.uade.edu.fain.ad.common.transfer.RemitoVO;

public class AdministracionSRVD implements AdministracionDelegate {

	private ServiceLocator<SwingProcessRemoto> locator;

	public AdministracionSRVD(ServiceLocator<SwingProcessRemoto> locator) {
		super();
		this.locator = locator;
	}

	public ServiceLocator<SwingProcessRemoto> getLocator() {
		return locator;
	}

	public SwingProcessRemoto getRemoteService()
			throws UnavailableServerException {
		return getLocator().getRemoteService();
	}

	@Override
	public List<NotaDevolucionVO> buscarDevoluciones() {
		try {
			return getRemoteService().buscarDevoluciones();
		} catch (RemoteException e) {
			throw new UnavailableServerException(
					"Error ejecutando remotamente.", e);
		} catch (UnavailableServerException e) {
			throw e;
		}
	}

	@Override
	public ImportacionRemitoVO procesarRemito(RemitoVO remitoVO)
			throws ProductoInexistenteException,
			OrdenCompraInexistenteException {
		try {
			return getRemoteService().procesarRemito(remitoVO);
		} catch (RemoteException e) {
			throw new UnavailableServerException(
					"Error ejecutando remotamente.", e);
		} catch (UnavailableServerException e) {
			throw e;
		}
	}

}
